<?php
  
  
  class LoginAction extends Action{
  
    //修改管理员密码
	
   public function savepass(){
   
 
        
	   
	    $re=M('adminuser')->where("username='%s'",$_POST['username'])->field('id')->find();
		$id=$re['id'];
		
		
		
		if(!empty($_POST)){
		
		   if(I('password')!=I('repass')){
		   $this->error('两次密码输入的不一致');
		   }
	      $_POST['id']=$id;
		  $_POST['password']=md5($_POST['password']);
		  
		  //dump($_POST);die;
		  $res=M('adminuser')->save($_POST);
		 
		  
		  if($res!==false){
		  
		     $this->success('密码修改成功');
		  }else{
		  
		    $this->error('修改失败');
		  }
		    
		  
		}
		//layout(false);
		
	//	dump($_SESSION);
		$this->display();
		
	 
	 }
  
     // 后台登录
	 
     public function login(){
	   
	   if(!empty($_POST)){
		   
		  // dump($_POST);
	     
		 if(I('username')=='' || I('password')==''){
		   $this->error("用户名或密码不能为空");
		 }
		
		 $re=M('adminuser')->where('username="%s" and password="%s"',I('username'),md5(I('password')))->find();
       //dump(M('adminuser')->getLastSql());die;
	   //dump($re);die;
		 if($re!=null){
		    
			
		   
		    session('adminname',$_POST['username']);
			
			session('adminislogin','2');
		   
		    $this->success("登陆成功",U('Index/index'));
			die;
			
		 }else{
		    $this->error('用户名或者密码错误');
			$this->display('Login/nologin');
			die;
		 }
		 
		 
	   }
	   
	   layout(false);
	   $this->display();
	 
	 }
	 
	 // 退出登录
	 public function outlogin(){
	     session(null);
		 $this->redirect('login');
	 
	 }
	
  
  }